/* 
 * File:   MtpSync.h
 * Author: arun
 *
 * Created on November 21, 2009, 6:02 PM
 */

#ifndef _MTPSYNC_H
#define	_MTPSYNC_H

#include <string>
#include <vector>
#include <libmtp.h>

using namespace std;

struct Track {
    string title;
    string artist;
    string album;
    int length;
    string filename;
    int mtpTrackId;
};

struct SyncInfo {
    vector<Track> toBeAdded;
    vector<Track> toBeDeleted;
};

class YBMtpSync {
public:
    YBMtpSync();
    YBMtpSync(const YBMtpSync& orig);
    bool connect();
    void disconnect();
    void synchronizeDevice(string rootPath, SyncInfo syncInfo);
    SyncInfo getSynchronizeDeviceInfo(vector<string> files);
    static Track extractTrackInfo(string filename);
    virtual ~YBMtpSync();
private:
    LIBMTP_mtpdevice_t* device;
    vector<Track> mtpTracks();
    void coutTrack(Track t);
    void coutTracks(vector<Track> localTracks);
    vector<Track> duplicateTracks(vector<Track> tracks);
    bool compareTracks(Track trackOne, Track trackTwo);
    void deleteTracks(vector<Track> tracks);
    vector<Track> getDifference(vector<Track> source, vector<Track> destination);
    void addTrack(string rootPath, Track track);
    void tokenize(const string& str, vector<string>& tokens, const string& delimiters = "/");
    int getParentId(vector<string> tokens);
    LIBMTP_folder_t* getOrCreateFolder(string folderName, LIBMTP_folder_t *folder);
    int sendTrack(char const* from_path, uint32_t parent_id, Track track);
    int addTrackToAlbum(LIBMTP_album_t *albuminfo, LIBMTP_track_t *trackmeta);
    LIBMTP_folder_t* getFolderById(LIBMTP_folder_t* folder, int id);
};

#endif	/* _MTPSYNC_H */

